package com.ihg.hiex.entity.session;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.ihg.hiex.entity.data.notice.EmailTemplate;
import com.ihg.hiex.entity.data.notice.Notice;

/**
 * 邮件通知
 * 
 * @author mohanlan
 *
 */
@Entity
@Table(name = "session_notification")
public class SessionNotification {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 所属session */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private Session session;
    
    /** 所属模板 */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private EmailTemplate template;
    
    /** 邮件通知代码 */
    private String code;
    
    /** 名称 */
    private String name;
    
    /** 描述 */
    @org.hibernate.annotations.Type(type = "text")
    private String description;
    
    /** 通知时间 */
    private Date occurTime;
    
    /** 通知类型 */
    @Enumerated(EnumType.STRING)
    private Notice notice;
    
    /** 创建时间 */
    private Date createTime;
    
    /** 是否发送 */
    @Column(name= "is_sent")
    private boolean sent;

    /** 关联delegate */
    private Long delegateId;
    
    /** 关联 assessor */
    private Long assessorId;
    
    @Column(name= "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public SessionNotification() {
    }
    
    /**
     * 
     * @param session
     * @param emailTemplate
     * @param occurTime
     */
    public SessionNotification(Session session, EmailTemplate emailTemplate, Date occurTime) {
        this.session = session;
        this.template = emailTemplate;
        this.code = emailTemplate.getCode();
        this.description = emailTemplate.getDescription();
        this.occurTime = occurTime;
        this.notice = emailTemplate.getNotice();
        this.createTime = new Date();
        this.sent = false;
        this.disabled = false;
    }
    
    /**
     * @param session
     * @param emailTemplate
     * @param occurTime
     * @param delegateId
     */
    public SessionNotification(Session session, EmailTemplate emailTemplate, Date occurTime, Long delegateId) {
        this.session = session;
        this.template = emailTemplate;
        this.code = emailTemplate.getCode();
        this.description = emailTemplate.getDescription();
        this.occurTime = occurTime;
        this.notice = emailTemplate.getNotice();
        this.createTime = new Date();
        this.sent = false;
        this.delegateId = delegateId;
        this.disabled = false;
    }
    
    /**
     * 
     * @param emailTemplate
     * @param assessorId
     */
    public SessionNotification(EmailTemplate emailTemplate, Long assessorId) {
        this.template = emailTemplate;
        this.code = emailTemplate.getCode();
        this.description = emailTemplate.getDescription();
        this.notice = emailTemplate.getNotice();
        this.assessorId = assessorId;
        this.createTime = new Date();
        this.sent = false;
        this.disabled = false;
    }
    
    /**
     * 
     * @param occurTime
     * @return
     */
    public SessionNotification editTime(Date occurTime) {
      this.occurTime = occurTime;
      
      return this;
    }
    
    /**
     * 
     * @return
     */
    public SessionNotification finish() {
    	this.sent = true;
    	return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the session
     */
    public Session getSession() {
        return session;
    }

    /**
     * @return the template
     */
    public EmailTemplate getTemplate() {
        return template;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @return the occurTime
     */
    public Date getOccurTime() {
        return occurTime;
    }

    /**
     * @return the notice
     */
    public Notice getNotice() {
        return notice;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the sent
     */
    public boolean isSent() {
        return sent;
    }

    /**
     * @return the delegateId
     */
    public Long getDelegateId() {
        return delegateId;
    }

    /**
     * @return the assessorId
     */
    public Long getAssessorId() {
        return assessorId;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param session the session to set
     */
    public void setSession(Session session) {
        this.session = session;
    }

    /**
     * @param template the template to set
     */
    public void setTemplate(EmailTemplate template) {
        this.template = template;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @param occurTime the occurTime to set
     */
    public void setOccurTime(Date occurTime) {
        this.occurTime = occurTime;
    }

    /**
     * @param notice the notice to set
     */
    public void setNotice(Notice notice) {
        this.notice = notice;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param sent the sent to set
     */
    public void setSent(boolean sent) {
        this.sent = sent;
    }

    /**
     * @param delegateId the delegateId to set
     */
    public void setDelegateId(Long delegateId) {
        this.delegateId = delegateId;
    }

    /**
     * @param assessorId the assessorId to set
     */
    public void setAssessorId(Long assessorId) {
        this.assessorId = assessorId;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
	
}